home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / gnu / fpu881 / src6.zoo / ldexp.cpp < prev    next >
C/C++ Source or Header  |  1991-09-24  |  1KB  |  54 lines

  1. # add exponent to floating point number
  2. # C Interface
  3. # double ldexp(double value, unsigned int exp);
  4. # returns value * 2**exp
  5. # (int is 16 bits if -mshort, 32 bits if !-mshort)
  6. # performed entirely on the 68881 to avoid overfow as good as possible
  7. ##############################################################################
  8. # hacked for the 68881 by Michael Ritzert, 5.10.90
  9. ##############################################################################
  10.  
  11. # addresses of the 68881 data port. This choice is fastest when much data is
  12. # transferred between the two processors.
  13.  
  14. comm =     -6    |    fpu command reg
  15. resp =    -16    |    fpu response reg
  16. zahl =      0    |    fpu data reg
  17.  
  18. # waiting loop ...
  19. #
  20. # wait:
  21. # ww:    cmpiw    #0x8900,a1@(resp)
  22. #     beq    ww
  23. # is coded directly by
  24. #    .byte    0x0c,0x69,0x89,0x00,0xff,0xf0,0x67,0xf8 (a1)
  25. #    or
  26. #    .long    0x0c6889000, 0x000067f8            (a0)
  27.  
  28.     .text; .even
  29.     .globl _ldexp
  30. _ldexp:
  31.     lea    0xfffa50,a0        | fpu address
  32.     movew    #0x4011,a0@(comm)    | ftwotox to fp0 (as long int!)
  33. #ifdef __MSHORT__
  34.     movew    a7@(12),d0        | get exponent
  35.     extl    d0
  36. #else
  37.     movel    a7@(12),d0        | get exponent
  38. #endif
  39.     cmpiw    #0x8900,a0@(resp)    | check if fpu is ready
  40.     movel    d0,a0@            | push arg
  41.     .long    0x0c6889000, 0xfff067f8    | wait
  42.     movew    #0x5423,a0@(comm)    | fmul value,fp0
  43.     .long    0x0c6889000, 0xfff067f8    | wait
  44.     movel    a7@(4),a0@        | load value
  45.     movel    a7@(8),a0@        |
  46.     .long    0x0c6889000, 0xfff067f8    | wait
  47.     movew    #0x7400,a0@(comm)    | get double from fp0
  48.     .long    0x0c6889000, 0xfff067f8    | wait
  49.     movel    a0@,d0
  50.     movel    a0@,d1
  51.     rts
  52.  
  53.     
  54.